package com.mk.service.platform;

import act.controller.Controller;
import cn.hutool.core.date.DateUtil;
import com.github.d925529.apidoc.ApiHttpMethod;
import com.github.d925529.apidoc.annotation.Api;
import com.github.d925529.apidoc.annotation.ApiMethod;
import com.github.d925529.apidoc.annotation.ApiParam;
import com.github.d925529.apidoc.annotation.ApiReturn;
import com.mk.domain.CuArticle;
import com.mk.interceptor.ITranslate;
import com.mk.util.S2;
import org.osgl.mvc.annotation.*;

import javax.inject.Inject;
import javax.validation.constraints.NotNull;

/**
 * 说明：服务
 * 作者：刘永盛
 * 日期：2018-7-2 19:52:54
 * 版本：1.0.0
 */
@Controller("cuArticle")
@Api(group = "pl", title = "服务", path = "/cuArticle")
@SuppressWarnings("unused")
public class CuArticleService extends BasePlatformService {
    @Inject
    private CuArticle.Mapper cuArticleMapper;


    @With({ILogin.class, ITranslate.class})
    @PostAction("add.json")
    @ApiMethod(title = "增加保存", path = "/add.json", method = ApiHttpMethod.POST)
    @ApiParam(name = "cuArticle", title = "", type = CuArticle.class)
    @ApiReturn(description = "主键", type = String.class)
    public String add(@NotNull CuArticle cuArticle) {
        String id = S2.UUID();
        cuArticle.setCaid(id);
        cuArticle.setCreatetime(DateUtil.now());
        cuArticle.setUserid(me.getUserid());
        cuArticleMapper.insertTemplate(cuArticle);
        return id;
    }


    @With({ILogin.class, ITranslate.class})
    @PutAction("update.json")
    @ApiMethod(title = "修改保存", path = "/update.json", method = ApiHttpMethod.PUT)
    @ApiParam(name = "cuArticle", title = "", type = CuArticle.class)
    @ApiReturn(description = "修改了的数量", type = int.class)
    public int update(@NotNull CuArticle cuArticle) {
        return cuArticleMapper.updateTemplateById(cuArticle);
    }

    @With(ILogin.class)
    @GetAction("view.json")
    @ApiMethod(title = "查询指定", path = "/view.json", method = ApiHttpMethod.GET)
    @ApiParam(name = "id", title = "的主键", type = String.class)
    @ApiReturn(description = "", type = CuArticle.class)
    public CuArticle view(@NotNull String id) {
        return cuArticleMapper.single(id);
    }

    @With(ILogin.class)
    @DeleteAction("deleteByid.json")
    @ApiMethod(title = "删除指定文章", path = "/deleteByid.json", method = ApiHttpMethod.DELETE)
    @ApiParam(name = "caid", title = "删除指定文章", type = String.class)
    @ApiReturn(description = "返回行数", type = int.class)
    public int deleteByid(@NotNull String caid) {
        return cuArticleMapper.deleteById(caid);
    }
}
